<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
${aier_doctype}
<html <s:property value="aier-html-xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}jc/chosen.css">
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/multiselect.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/school/smanage.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/multiselect.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript"
	src="${aier_js_url}social/school/attend/smlea.js"></script>
<script type="text/javascript">
	var global_suffix = "${aier_suffix}", global_url = "${aier_url}", global_uri = "${aier_uri}", global_urijs = "${aier_urijs}", 
		global_sid = "${sid}", global_tid = "${tid}";

</script>
</head>
<!-- 请假管理 -->
<body>


	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user"
		executeResult="true"></s:action>

	<!-- 正文 -->
	<div id="hfContent" class="ar-content">
		<div class="content-main">
			<!-- 学校名称栏 -->
			<s:action name="scomm_schoolMTitle" namespace="/school"
				executeResult="true"></s:action>
			<div class="main-content wrap-bg clearfix">
				<!-- 左侧栏 -->
				<s:action name="scomm_schoolMLeft" namespace="/school"
					executeResult="true"></s:action>
				<!-- 右侧内容 -->
				<div class="ae-right">
					<div class="right-main">
						<div class="right-main-top">
							<div class="binfo-title">
								<h3>请假管理</h3>
							</div>
							<div class="right-line"></div>
						</div>
						<div class="right-main-c">
							<div class="info-tab01">
								<table id="inviteParTable">
									<tbody>
										<tr>
											<th class="gray6">起始时间：</th>
											<td><input type="text" id="startTime" class="PY-input"
												onfocus="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
											</td>
											<th class="gray6">结束时间：</th>
											<td><input type="text" id="EndTime" class="PY-input"
												onfocus="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
											</td>

										</tr>
										<tr>
											<th class="gray6">姓名与账户：</th>
											<td><s:select id="selTname" list="tnameAccountList"
													data-placeholder="请选择或输入姓名与账号" cssClass="chosen"
													tabindex="4">
												</s:select>
											</td>
											<th class="gray6">职务：</th>
											<td><select id="selTgrade" data-placeholder="请选择或输入职务"
												class="chosen" tabindex="1">
													<option value="-1">请选择</option>
													<c:forEach var="sg" items="${schoolGradeList }">
														<option value="${sg.gid}">${sg.name}</option>
													</c:forEach>
											</select>
											</td>

										</tr>
										<tr>
											<th class="gray6">请假类型：</th>
											<td><select id="leave_type_handle" Class="chosen">
													<option value="-1">请选择</option>
													<c:forEach var="leaveHandle" items="${leaveTypeHandleMap }">
														<option value="${leaveHandle.key}">${leaveHandle.value}</option>
													</c:forEach>
											</select>
											</td>
											<td colspan="2"><button onclick="search()"
													style="margin-left: 225px;"
													class="b_lmSel ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
													role="button" aria-disabled="false">
													<span class="ui-button-text">查询</span>
												</button></td>
										</tr>
										<tr>
											<th class="gray6">请假操作：</th>
											<td colspan="5"><a id="b_lmadd" href="javascript:;"
												class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr"
												role="button" aria-disabled="false"><span
													class="ui-button-text">添加请假</span> </a> <a id="b_lmadditional"
												href="javascript:;"
												class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr"
												role="button" aria-disabled="false"><span
													class="ui-button-text">添加补假</span> </a> <a id="b_lmexception"
												href="javascript:;"
												class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr"
												role="button" aria-disabled="false"><span
													class="ui-button-text">添加异常处理</span> </a></td>
										</tr>
									</tbody>

								</table>
							</div>

						</div>
						<div class="right-main-down">
							<div class="down-line"></div>

							<div class="down-inre">
								<table id="leaveinfo"></table>
								<div id="leavepage"></div>
							</div>
						</div>
					</div>
				</div>
			</div>

		</div>
		<!-- footer copyright -->
		<s:action name="userhomecomm_homeFooter" namespace="/user"
			executeResult="true"></s:action>
		<!-- /footer copyright -->
	</div>



	<!-- 弹出层添加请假 -->
	<div id="d_leaveadd" style="display: none;" title="添加请假">
		<div class="info-tab01">
			<table>
				<tbody>
					<tr>
						<th class="gray6">教师姓名与账户：</th>
						<td><s:select id="selTname_add" list="tnameAccountList" data-placeholder="请选择或输入姓名与账号" 
								cssClass="chosen" tabindex="4">
							</s:select>
						</td>
					</tr>
					<tr>
						<th class="gray6">请假类型：</th>
						<td colspan="3">
							<div class="d-type">
								<s:radio name="sel_type_resone" list="leaveTypeResoneMap" listKey="key" listValue="value" value="2" ></s:radio>
							</div></td>
					</tr>
					<tr>
						<th class="gray6">开始时间：</th>
						<td><input type="text" id="txt_addst" class="PY-input"
							onfocus="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
						</td>
						<th class="gray6">结束时间：</th>
						<td><input type="text" id="txt_addet" class="PY-input"
							onfocus="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
						</td>
					</tr>
					<tr>
						<th class="gray6" valign="top">请假原因：</th>
						<td colspan="3"><textarea class="slmtextarea" id="txt_desinfo"></textarea></td>
					</tr>

				</tbody>
			</table>
		</div>

	</div>

	<!-- 撤销请假弹出层 -->
	<div id="leave_del" style="display: none;" title="撤销请假">
		您确定要将<span id="deltname"></span> 的这条请假信息撤销吗?
	</div>

	<!-- 弹出层补假 -->
	<div id="d_leaveadditional" style="display: none;" title="补假">
		<div class="info-tab01">
			<table>
				<tbody>
					<tr>
						<th class="gray6">教师姓名与账户：</th>
						<td><s:select id="selTname_old" list="tnameAccountList" data-placeholder="请选择或输入姓名与账号" 
								cssClass="chosen" tabindex="4">
							</s:select>
						</td>
					</tr>
					<tr>
						<th class="gray6">请假类型：</th>
						<td colspan="3">
							<div class="d_type">
								<s:radio name="sel_type_resone_old" list="leaveTypeResoneMap" listKey="key" listValue="value" value="2" ></s:radio>
							</div></td>
					</tr>
					<tr>
						<th class="gray6">开始时间：</th>
						<td><input type="text" id="txt_addst_additional"
							class="PY-input"
							onfocus="WdatePicker({skin:'twoer',startDate:'%y-%M-%d %H:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
						</td>
						<th class="gray6">结束时间：</th>
						<td><input type="text" id="txt_addet_additional"
							class="PY-input"
							onfocus="WdatePicker({skin:'twoer',startDate:'%y-%M-%d %H:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
						</td>
					</tr>
					<tr>
						<th class="gray6" valign="top">请假原因：</th>
						<td colspan="3"><textarea id="txt_desinfo_additional" class="slmtextarea"></textarea></td>
					</tr>

				</tbody>
			</table>
		</div>


	</div>

	<!-- 弹出层内容 (异常请假处理)-->
	<div id="d_leaveexception" style="display: none;" title="添加异常请假处理">
		
		<div class="info-tab01">
			<table>
				<tbody>
					<tr>
						<th class="gray6">职务：</th>
						<td><select id="selTgrade_exp" data-placeholder="请选择或输入职务" onchange="changetypeexc()"
							Class="chosen" tabindex="1">
								<option value="-1">所有职务</option>
								<c:forEach  var="sg" items="${schoolGradeList }">
									<option value="${sg.gid}">${sg.name}</option>
								</c:forEach>
						</select></td>
					</tr>				
					<tr>
						<th class="gray6">教师姓名与账户：</th>
						<td><div class="sel_position" id="sel_position_teacher_exc">
							<s:select id="selTname_exp" list="tnameAccountList" data-placeholder="请选择或输入姓名与账号" 
								cssClass="chosen" tabindex="4">
							</s:select>
							</div>
						</td>
					</tr>
					
					<tr>
						<th class="gray6">开始时间：</th>
						<td>
						<input type="text" class="PY-input" id="txt_exceptionst" onfocus="WdatePicker({skin:'twoer',startDate:'%y-%M-%d %H:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
						</td>
						<th class="gray6">结束时间：</th>
						<td>
						<input type="text" class="PY-input" id="txt_exceptionet" onfocus="WdatePicker({skin:'twoer',startDate:'%y-%M-%d %H:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
						</td>
					</tr>
					<tr>
						<th class="gray6" valign="top">请假原因：</th>
						
						<td colspan="3">
							<div class="d_type">
								<s:radio name="sel_type_resone_exception" list="leaveExceptionResoneMap" listKey="key" listValue="value" value="5"  onclick="reasonDefault()"></s:radio>
							</div>	
						<textarea id="txt_desinfo_addException" class="slmtextarea">
								
						</textarea></td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</body>
<script type="text/javascript">

	$(".chosen").chosen();
	$(function() {
		// 请假弹出层
		$("#d_leaveadd").dialog({
			//背景变暗
			modal: true,
			autoOpen : false,
			show : "fade",
	        hide : "fade",
			width : "670",
			height : "410",
			buttons: {
				"确定": function() {
					addTel();
					$( this ).dialog( "close" );
				},"取消": function() {
					$( this ).dialog( "close" );
				}
			},
		close: function() {
		}
		});
		$("#b_lmadd").click(function() {
			$("#d_leaveadd").dialog("open");
			return false;
		});
		
		
		// 补假弹出层
		$("#d_leaveadditional").dialog({
			//背景变暗
			modal: true,
			autoOpen : false,
			show : "fade",
	        hide : "fade",
			width : "670",
			height : "410",
			buttons: {
				"确定": function() {
					addTel();
					$( this ).dialog( "close" );
				},"取消": function() {
					$( this ).dialog( "close" );
				}
			},
		close: function() {
		}
		});
		$("#b_lmadditional").click(function() {
			$("#d_leaveadditional").dialog("open");
			return false;
		});
		
		// 异常处理弹出层
		$("#d_leaveexception").dialog({
			//背景变暗
			modal: true,
			autoOpen : false,
			show : "fade",
	        hide : "fade",
			width : "670",
			height : "410",
			buttons: {
				"确定": function() {
					addTel();
					$( this ).dialog( "close" );
				},"取消": function() {
					$( this ).dialog( "close" );
				}
			},
		close: function() {
		}
		});
		$("#b_lmexception").click(function() {
			$("#d_leaveexception").dialog("open");
			return false;
		});
	});
	
	
	//查询请假列表信息
	function search(){
		var nameAndAccount = $("#selTname").val();
		if(nameAndAccount=="请选择"){
			var taccount = "";	
		}else{
			var taccount = nameAndAccount.split(" ")[1];
		}
		var typeId = $('#selTgrade  option:selected').val();
		var type_handle = $('#leave_type_handle  option:selected').val();
		var txt_sdate = $('#startTime').val();
		var txt_edate = $('#EndTime').val();
		jQuery("#leaveinfo").jqGrid('setGridParam',{url:"${aier_url}${aier_urijs}schoollea_searchLeaList_admin${aier_suffix}?sid="+global_sid+"&account="+taccount
			+"&gid="+typeId+"&type_handle="+type_handle+"&txt_sdate="+txt_sdate+"&txt_edate="+txt_edate,page:1}).trigger("reloadGrid");
	}

	//添加请假
	function addTel(){
		var nameAndAccount = $("#selTname_add").val();
		if(nameAndAccount=="请选择"){
			var taccount_add = "";	
		}else{
			var taccount_add = nameAndAccount.split(" ")[1];
		}
		var type_resone = $("input[name='sel_type_resone']:checked").val();
		var txt_sdate_add = $('#txt_addst').val();
		var txt_edate_add = $('#txt_addet').val();		
		var txt_desinfo = $('#txt_desinfo').val();	
		if(taccount_add==""){
			$().message("请选择一个教师!");
			return;
		}
		if(txt_sdate_add.trim()==""){
			$().message("请输入请假开始时间");
			return
		}
		if(txt_edate_add.trim()==""){
			$().message("请输入请假结束时间");
			return
		}
		if(txt_edate_add<txt_sdate_add){
			$().message("结束时间必须大于等于开始时间");
			return
		}
		if(txt_sdate_add<curtime){
			$().message("今天之前的请假 请走补假流程");
			return
		}
		var fun = function(data) {
			if(1==data.s){
				$().message("添加成功,您可以继续添加!");
				$("#leaveinfo").trigger("reloadGrid");
			}else{
				$().message("添加失败,请稍后再试!");
			}
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoollea_add_admin${aier_suffix}"), fun, 
			{"sid" : global_sid,"account" :taccount_add,"txt_sdate":txt_sdate_add,"txt_edate":txt_edate_add,
			"type_resone":type_resone,"txt_desinfo":txt_desinfo,"tid":global_tid});
				
	}
	
	//补假
	function additional(){
		var nameAndAccount = $("#selTname_old").val();
		if(nameAndAccount=="请选择"){
			var taccount_add = "";	
		}else{
			var taccount_add = nameAndAccount.split(" ")[1];
		}
		var type_resone = $("input[name='sel_type_resone_old']:checked").val();
		var txt_sdate_add = $('#txt_addst_additional').val();
		var txt_edate_add = $('#txt_addet_additional').val();		
		var txt_desinfo = $('#txt_desinfo_additional').val();	
		
		if(taccount_add==""){
			$().message("请选择一个教师!");
			return;
		}
		if(txt_sdate_add.trim()==""){
			$().message("请输入请假开始时间");
			return
		}
		if(txt_edate_add.trim()==""){
			$().message("请输入请假结束时间");
			return
		}
		if(txt_edate_add<txt_sdate_add){
			$().message("结束时间必须大于等于开始时间");
			return
		}
        if (txt_edate_add >= curtime) {
        	$().message("请输入早于今天的请假开始时间");
			return
        }
		
		var fun = function(data) {
			if(1==data.s){
				$().message("添加成功,您可以继续添加!");
				$("#leaveinfo").trigger("reloadGrid");
			}else{
				$().message("添加失败,请稍后再试!");
			}
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoollea_additional${aier_suffix}"), fun, 
			{"sid" : global_sid,"account" :taccount_add,"txt_sdate":txt_sdate_add,"txt_edate":txt_edate_add,
			"type_resone":type_resone,"txt_desinfo":txt_desinfo,"tid":global_tid});
							
	}
	
	//改变职务(异常处理) abnormalTname
	function changetypeexc(){
		var typeId_exception = $('#selTgrade_exp option:selected').val();
		var fun = function(data) { 
			var t = "<select id='selTname_exp' Class='chosen' tabindex='1' ><option value='请选择'>请选择</option>";
			if(data.tnameAccountList!=null&&data.tnameAccountList.length>0){
				for ( var i = 0; i < data.tnameAccountList.length; i++) {
					var tnameAccount = data.tnameAccountList[i];
					t += "<option value="+tnameAccount+">" + tnameAccount + "</option>";
				}
			};
			t += "</select>";
			$('#sel_position_teacher_exc').html(t);
			$(".chosen").chosen();
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoollea_changetype${aier_suffix}"), fun, 
			{"sid" : global_sid,"gid" :typeId_exception});
	}
	
	//异常处理
	function addExceptionTel(){
		var nameAndAccount = $("#selTname_exp").val();
		if(nameAndAccount=="请选择"){
			var account_add = "";	
		}else{
			var account_add = nameAndAccount.split(" ")[1];
		}
		var typeId_exception = $('#selTgrade_exp option:selected').val();
		var txt_sdate_add = $('#txt_exceptionst').val();
		var txt_edate_add = $('#txt_exceptionet').val();
		var txt_desinfo_exception = $('#txt_desinfo_addException').val();
		var type_resone_exception = $("input[name='sel_type_resone_exception']:checked").val();
		
		if(typeId_exception==-1 && account_add==""){
			$().message("请选择一个职务或教师");
			return;
		}		
		if(txt_sdate_add.trim()==""){
			$().message("请输入请假开始时间");
			return
		}
		if(txt_edate_add.trim()==""){
			$().message("请输入请假结束时间");
			return
		}
		if(txt_edate_add<txt_sdate_add){
			$().message("结束时间必须大于等于开始时间");
			return
		}
		if(account_add==""){
			if (!confirm("确定要给该职务的所有老师添加请假信息吗？")) 
			return
		}
		
		var fun = function(data) {
			if(1==data.s){
				$().message("添加成功,您可以继续添加!");
				$("#leaveinfo").trigger("reloadGrid");
			}else{
				$().message("添加失败,请稍后再试!");
			}
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoollea_addException${aier_suffix}"), fun, 
			{"sid" : global_sid,"account" :account_add,"txt_sdate":txt_sdate_add,"txt_edate":txt_edate_add,"gid":typeId_exception,
			"txt_desinfo" :txt_desinfo_exception,"type_resone":type_resone_exception,"tid":global_tid});
				
		
		
	}
	


	
	
	//异常原因默认值
	function reasonDefault(){
		var value = $("input[name='sel_type_resone_exception']:checked").val();
		if(1==value){
			//忘带卡
			$("#txt_desinfo_addException").val("忘记带卡，已登记。");
		}else if(2==value){
			//卡损坏
			$("#txt_desinfo_addException").val("卡已损坏或丢失，已登记。");
		}
		else if(3==value){
			//请假未批
			$("#txt_desinfo_addException").val("已请假，请求审批。");
		}
		else if(4==value){
			//门禁异常
			$("#txt_desinfo_addException").val("门禁异常。");
		}
		else if(5==value){
			//其他
			$("#txt_desinfo_addException").val("");
		}

	}
	
</script>
</html>